package com.auto.learning.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class CustomViewPager extends ViewPager {

	private boolean isCanScroll = true;

	public CustomViewPager(Context context) {
		super(context);
	}

	public CustomViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void setScanScroll(boolean isCanScroll) {
		this.isCanScroll = isCanScroll;
	}

	/*@Override
	protected boolean canScroll(View v, boolean arg1, int arg2, int arg3, int arg4) {
		if (!isCanScroll) {
			if (v instanceof ViewPager) {
				int currentItem = ((ViewPager) v).getCurrentItem();
				if ((currentItem == 1)) {
					return true;
				}
				return false;
			}
		}
		return super.canScroll(v, arg1, arg2, arg3, arg4);
	}*/

	@Override
	public boolean onInterceptTouchEvent(MotionEvent arg0) {
		if (isCanScroll) {
			return super.onInterceptTouchEvent(arg0);
		} else {
			// false 不能左右滑动
			return false;
		}
	}

}